//express_demo.js 
var express = require('express');
var app = express();
var nodeCmd = require("node-cmd")
 
// hello
app.get('/hello', function (req, res) {
   res.send('Hello World');
})

//conver shp to geojson
app.get('/shp2json', function (req, res) {
    shp2json();
   res.send('complete!');
})

// get parameter from request example
app.get('/getParam', function (req, res) {
    console.log(req.query._url)
   res.send('complete!');
})

 
var server = app.listen(8081, function () {
 
  var host = server.address().address
  var port = server.address().port
 
  console.log("应用实例，访问地址为 http://%s:%s", host, port)
 
})

//the command need to revise
function shp2json(){
    nodeCmd.run('mapshaper data/guangzhou.shp -simplify dp interval=100 -o data/json/ format=geojson')
}
